var generate = function (numRows) {
    // 创建一个二维数组
    let triangle = [];
    for (let i = 0; i < numRows; i++) {
        // 创建一个新的数组来存储当前行的元素
        let rotrianglew = new Array(i + 1);
        triangle.push(rotrianglew);
        for (let j = 0; j <= i; j++) {
            if (j == 0 || j == i) rotrianglew[j] = 1;
            else if (j == 0 && i !== 0) rotrianglew[j] = triangle[i - 1][j];
            else if (j == i && i !== 0) rotrianglew[j] = triangle[i - 1][j - 1];
            else {
                rotrianglew[j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
            }
        }
        // console.log(rotrianglew);
    }
    return triangle;
};
console.log(generate(5));


// let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// console.log(arr[-1] + 1);//undefined


